package cn.yeziji.forum.controller;

import cn.yeziji.forum.common.ForumResult;
import cn.yeziji.forum.common.Paging;
import cn.yeziji.forum.dao.intf.ForumFeedbackDao;
import cn.yeziji.forum.dto.feedback.FeedbackDTO;
import cn.yeziji.forum.exception.FeedbackException;
import cn.yeziji.forum.common.enums.status.FeedbackStatus;
import cn.yeziji.forum.utils.ForumResultUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 反馈控制器
 *
 * @author gzkemays
 * @since 2022/11/05 6:08 PM
 */
@RestController
@RequestMapping("/feedback")
public class ForumFeedbackController {
  @Resource ForumFeedbackDao feedbackDao;

  @PostMapping("/commit")
  public ForumResult commit(@Valid @RequestBody FeedbackDTO dto) {
    if (dto.getContent().trim().equals("H4sIAAAAAAAAAwMAAAAAAAAAAAA=")) {
      throw new FeedbackException(FeedbackStatus.CONTENT_IS_BLANK);
    }
    feedbackDao.commit(dto);
    return ForumResultUtils.ok(null, "反馈成功");
  }

  @GetMapping("/list")
  public ForumResult commit(Paging paging) {
    return ForumResultUtils.ok(feedbackDao.list(paging));
  }
}
